package com.hue.controller;

import com.hue.entity.R;
import com.hue.service.OSSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/oss")
@CrossOrigin
public class OSSController {
    @Autowired
    private OSSService ossService;

    @PostMapping("/upload")
    public R upload(MultipartFile file){
        try {
            String url = ossService.upload(file);
            return R.ok().data("url",url);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error().data("error",e.getMessage());
        }
    }
}
